#Universal Molotilka 1.0
#Copyright (c) 2011, 2012, Alexey Silaev ArchFurry@gmail.com
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without modification,
#are permitted provided that the following conditions are met:
#
#    * Redistributions of source code must retain the above copyright notice, this 
#		list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright notice, 
#		this list of conditions and the following disclaimer in the documentation
#		and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
#INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
#LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
#OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
#OF THE POSSIBILITY OF SUCH DAMAGE.


CC=gcc
LDFLAGS=-static

LIBS=-L. -lum
CFLAGS=-O2 -I.

NAME=umc
PREFIX=/usr/local
OBJS=cipher.o cipher_init.o hash.o common.o random.o stream.o
HEADERS=cipher.h cipher_init.h hash.h common.h random.h stream.h
all: libum cli

libum: $(OBJS)
	ar rcs libum.a $(OBJS)
cli: cli.c libum
	$(CC) $(CFLAGS) -o $(NAME) cli.c $(LIBS)
clean: 
	rm -f *.o *.a *.exe $(NAME) *.key *.pf2 *.out umc.h stream_test
install:
	cp $(NAME) $(PREFIX)/bin
	cp libum.a $(PREFIX)/lib
	cp libum.h $(PREFIX)/include
uninstall:
	rm -f $(PREFIX)/bin/$(NAME)
	rm -f $(PREFIX)/lib/libum.a
	rm -f $(PREFIX)/include/libum.h
cipher.o: cipher.c
	$(CC) $(CFLAGS) -c cipher.c
cipher_init.o: cipher_init.c
	$(CC) $(CFLAGS) -c cipher_init.c
hash.o: hash.c
	$(CC) $(CFLAGS) -c hash.c
common.o: common.c
	$(CC) $(CFLAGS) -c common.c
random.o: random.c
	$(CC) $(CFLAGS) -c random.c
stream.o: stream.c
	$(CC) $(CFLAGS) -c stream.c

test:
	$(CC) $(CFLAGS) -o stream_test stream_test.c $(LIBS)
	./stream_test
	./$(NAME) -i readme.txt -o readme.pf2 -p VerySecretPasswoRD
	./$(NAME) -d -i readme.pf2 -o readme.out -p VerySecretPasswoRD
	cmp readme.out readme.txt